<?php
/**
 * Created by PhpStorm.
 * User: zzw
 * Date: 17-4-14
 * Time: 下午3:54
 */
if (!defined('BASEPATH')) {
    exit('No direct script access allowed');
}
class Company extends API_Controller
{
    function __construct()
    {
        parent::__construct();
        $this->load->model('company_model', 'mcompany');
        $this->load->model('category_model','mcategory');
        $this->load->model('account_info_model','maccount_info');
    }
    public function index() {
        $this->_auto();
        if(isset($this->data['company']) && $this->data['company']) {
            $company_id = $this->data['company'];
        } else {
            $company_id = $this->userinfo['ctype'] == 1 ? $this->userinfo['company'] : '';
        }
        if($company_id) {
            $info = $this->mcompany->get_one($company_id);
            if($this->userinfo['id'] != $info['uid']){
                $this->mcompany->add_scan($company_id);
            }
            $info['user'] = $this->macc->get_one($info['uid'],'id,uname,position');
            if($info['user']['id'] == $this->userinfo['id']) {
                $info['user']['is_toke'] = 0;
            } else {
                $info['user']['is_toke'] = 1;
            }
            $userInfo = $this->maccount_info->get_one(array('uid'=>$info['uid']),'tags');
            $info['tags'] = $userInfo['tags'] ?  get_mcategory_titles($userInfo['tags']) : '';
            $info['users'] = $this->macc->get_all(array('company'=>$info['id'],'audit'=>0,'status'=>2,'ctype'=>1,'id <>'=>$info['uid']),'id,uname,position');
            foreach($info['users'] as &$row) {
                $row['is_toke'] = $row['id'] == $this->userinfo['id'] ? 0 : 1;
            }

            $logo = $info['photo'] ? one_upload($info['photo']) : '';
            $info['logo'] = $logo ? UPLOAD_URL.$logo['url'] : '';
            $plan = $info['plan'] ? one_upload($info['plan']) : '';
            $info['plan'] = $plan ? UPLOAD_URL.$plan['url']: '';
            $info['thumb'] = $info['thumb'] ? UPLOAD_URL.$info['thumb']: '';
            $com_industry = explode(',',$info['industry']);
            $industry = $this->mcategory->get_all(array('ctype'=>24,'in'=>array('id',$com_industry)),'id,title');
            $info['industry'] = $industry;
            $info['desc'] = content_nbsp(content_br($info['desc']));
            $info['fund'] = content_nbsp(content_br($info['fund']));
            $info['pdesc'] = content_nbsp(content_br($info['pdesc']));
            $info['operation'] = content_nbsp(content_br($info['operation']));
            $info['team'] = content_nbsp(content_br($info['team']));
            // 返回成功
            $this->vdata['returnCode'] = '200';
            $this->vdata['returnInfo'] = '操作成功';
            $this->vdata['secure'] = JSON_SECURE;
            $this->vdata['content'] = $info;
        } else {
            // 返回失败
            $this->vdata['returnCode'] = '00111';
            $this->vdata['returnInfo'] = '操作失败';
            $this->vdata['secure'] = JSON_SECURE;
            $this->vdata['content'] = '';
        }

        $this->_send_json($this->vdata);
    }
    /**
     * 企业动态
     */
    public function activity() {

    }
}